package com.examples.demo3;

import com.google.inject.Guice;
import com.google.inject.Inject;
import com.google.inject.name.Named;
import com.google.inject.name.Names;
import lombok.val;

/**
 * 一个接口有多个实现，又不想写过多的注解类，
 * 于是Guice提供了其它注入方式来解决此问题。比如下面的。
 */
public class MultiInterfaceServiceDemo2 {
    @Inject
    @Named("WWW")
    private Service wwwService;
    @Inject
    @Named("Home")
    private Service homeService;

    public static void main(String[] args) {
        val misd = Guice.createInjector(binder -> {
                    binder.bind(Service.class).annotatedWith(Names.named("WWW")).to(WWWService.class);
                    binder.bind(Service.class).annotatedWith(Names.named("Home")).to(HomeService.class);
                }
        ).getInstance(MultiInterfaceServiceDemo2.class);
        misd.homeService.execute();
        misd.wwwService.execute();
    }
}
